Helpful Information
 
 
Category: Client side development
"save my place"

My pages are pretty lengthy with a lot of information and I was looking for a code that might help my viewers to click on a line or section to help them "save their place", so that when they finish reading they can go back to where they clicked.

Does anyone know of such a code? If not, could you point me in the right direction where I can get help?

Thanks
eyecnn

Works in ie4+, ns6, mozilla 1.0. I labeled everything in case you want to use something else than a keypress.

<html>

<head>

<script>

// START OF - keypress script

function key (e) {
var thekey =
document.layers ? e.which :
document.all ? event.keyCode :
document.getElementById ? e.keyCode : 0;
if (thekey==16) { savepos(); }
if (thekey==17) { jump(); }
return false;
}

// END OF - keypress script

// START OF - browser detect

ns6 = false;
ie4 = false;
if (navigator.appName=="Netscape"&&parseInt(navigator.appVersion)>=5) { ns6 = true; }
if (navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)>=4) { ie4 = true; }

// END OF - browser detect

// START OF - save position script

function savepos() {
if (ie4) {
ypos = document.body.scrollTop;
xpos = document.body.scrollLeft;
}
if (ns6) {
xpos = window.pageXOffset;
ypos = window.pageYOffset;
}
}

// END OF - save position script

// START OF - return to save point

function jump() {
window.scrollTo(xpos,ypos)
}

// END OF - return to save point

</script>

</head>

<body onkeydown="return key(event);">

Press Shift to save a point.<br>
Press Ctrl to return to that save point.

</body>

</html>

If you want to change what key is pressed to do what use the following script:

<html>

<head>

<script>
function key (e) {
var thekey =
document.layers ? e.which :
document.all ? event.keyCode :
document.getElementById ? e.keyCode : 0;
window.status=thekey;
return false;
}

</script>

</head>

<body onkeydown="return key(event)">

</body>

</html>

When you press a key it gives you the keycode in the status bar.

x_goose_x

Thanks so much, I really appreciate the code!

Candy










privacy (GDPR)